﻿<BadHabit_Factory_Controls:GenericPanel
    x:Name="backlogPanel"
    x:Class="BadHabit.Factory.Controls.BacklogPanel"
    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:core="clr-namespace:System;assembly=mscorlib"    
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"        
    xmlns:BadHabit_Factory_Converters="clr-namespace:BadHabit.Factory.Converters"  
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"       
    xmlns:BadHabit_WPFTools_Converters="clr-namespace:BadHabit.WPFTools.Converters;assembly=BadHabit.WPFTools"
    xmlns:Microsoft_Toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    xmlns:BadHabit_Factory="clr-namespace:BadHabit.Factory"
    
     xmlns:props="clr-namespace:BadHabit.Factory.Properties"
   
    DataContextChanged="backlogPanel_DataContextChanged"
    
    Loaded="backlogPanel_Loaded"
   
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Background="Transparent">
    
    <BadHabit_Factory_Controls:GenericPanel.CommandBindings>        
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.PlanSprint" CanExecute="PlanSprint_CanExecute" Executed="PlanSprint_Executed"/>        
        <CommandBinding Command="BadHabit_Factory:FactoryCommands.AddSprint"  Executed="AddSprint_Executed"/>                
        <CommandBinding Command="ApplicationCommands.Save" CanExecute="Save_CanExecute" Executed="Save_Executed"/>
    </BadHabit_Factory_Controls:GenericPanel.CommandBindings>
    
    <BadHabit_Factory_Controls:GenericPanel.Resources>
        <BadHabit_Factory_Converters:BaseLineConverter x:Key="BaseLineConverter"/>
        <BadHabit_Factory_Converters:VelocityIsHigherConverter x:Key="VelocityIsHigherConverter"/>
        

        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type core:Enum}" x:Key="BacklogFilterList">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="BadHabit_Factory_Controls:BacklogFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <DataTemplate x:Key="BacklogFilterSelectedItem">
            <StackPanel Orientation="Horizontal" Margin="0,0,5,0">
                <TextBlock Text="{x:Static props:Resources.Viewing}" FontStyle="Italic"/>
                <TextBlock Text="{Binding ., Converter={StaticResource LocalizeConverter}}" Margin="5,0,0,0"/>
            </StackPanel>            
        </DataTemplate>

        <DataTemplate x:Key="BacklogFilterItem">            
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="40"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image Style="{StaticResource BacklogFilterImage}" Grid.Column="0" Grid.RowSpan="2" Width="32" Height="32" />
                <TextBlock
                    Text="{Binding ., Converter={StaticResource LocalizeConverter}}"
                    Margin="5,0,0,0" FontWeight="Bold" TextAlignment="Left" HorizontalAlignment="Stretch" Foreground="{StaticResource DarkTextBrush}" Grid.Column="1" Grid.Row="0"/>
                <TextBlock 
                    
                    Margin="5,0,0,0" HorizontalAlignment="Stretch" TextAlignment="Left" Grid.Column="1" Grid.Row="1">
                    <TextBlock.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding}" Value="FULL_BACKLOG">
                                    <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.FULL_BACKLOG_tooltip}"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding}" Value="SELECTED_BACKLOG">
                                    <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.SELECTED_BACKLOG_tooltip}"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding}" Value="PLANNED_BACKLOG">
                                    <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.PLANNED_BACKLOG_tooltip}"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </Grid>            
        </DataTemplate>




    </BadHabit_Factory_Controls:GenericPanel.Resources>

    <Grid x:Name="ContentPanel" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <DockPanel Grid.Row="0">
            <ToolBar DockPanel.Dock="Left" ToolBarTray.IsLocked="True" Height="60">


                <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,5,0" DataContext="{Binding Project}">
                <TextBlock
                    MaxWidth="100"
                    Text="{Binding Baseline, Converter={StaticResource BaseLineConverter}}"  Style="{StaticResource ToolBarBigTextBlock}" HorizontalAlignment="Center" TextWrapping="WrapWithOverflow"/>
                
            </StackPanel>
                        
            <StackPanel Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Project}">
                <TextBlock Text="{Binding TotalSize}" Style="{StaticResource ToolBarBigTextBlock}" />
                <TextBlock Text="{x:Static props:Resources.points}"  Style="{StaticResource ToolBarBigTextBlock}" FontSize="12" />
            </StackPanel>

            <StackPanel Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Project}">
                <TextBlock Text="{Binding TotalHours}"  Style="{StaticResource ToolBarBigTextBlock}" />
                <TextBlock Text="{x:Static props:Resources.hours}"  Style="{StaticResource ToolBarBigTextBlock}"  FontSize="12" />
            </StackPanel>

            <StackPanel Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Project}">
                <TextBlock Text="{Binding PlannedVelocity, StringFormat='{}{0:F1}'}">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock" BasedOn="{StaticResource ToolBarBigTextBlock}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding PlannedVelocity, Converter={StaticResource VelocityIsHigherConverter}}" Value="True">
                                <Setter Property="TextBlock.Foreground" Value="{StaticResource AlertValueBrush}"/>
                            </DataTrigger>
                        </Style.Triggers>                                
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
                <TextBlock Text="{x:Static props:Resources.velocity}" FontSize="12" Style="{StaticResource ToolBarBigTextBlock}" />                                                               
            </StackPanel>

                   
            
            <Separator/>


                <Menu>

                    <MenuItem
                        x:Name="addItemButton"
                        BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                        Click="addItemButton_Click"
                        ToolTip="{x:Static props:Resources.Add_Item_tooltip}"
                        Header="{x:Static props:Resources.Add_Item}"                                    
                        Style="{StaticResource ToolBarMenuItem}">
                        <MenuItem.Icon>
                            <Image Source="/Images/BacklogItemStatus/itemDONE.png" Stretch="Uniform" Width="32" Height="32"/>
                        </MenuItem.Icon>
                    </MenuItem>


                    <MenuItem   
                    x:Name="addSprintButton"                                        
                    BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                    Header="{x:Static props:Resources.Add_Sprint}"                                     
                    Style="{StaticResource ToolBarMenuItem}"
                    CommandTarget="{Binding ElementName=backlogDataGrid}"                               
                    Command="BadHabit_Factory:FactoryCommands.AddSprint">
                        <MenuItem.Icon>
                            <Image Source="/Images/ToolBar/add.png" Stretch="Uniform" Width="32" Height="32"/>
                        </MenuItem.Icon>
                    </MenuItem>

                </Menu>
                
                <Separator/>
                <Menu>

                <MenuItem   
                    x:Name="planSprintButton"                                        
                    BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                    Header="{x:Static props:Resources.Re_Plan}"                                     
                    Style="{StaticResource ToolBarMenuItem}"
                    CommandTarget="{Binding ElementName=backlogDataGrid}"                               
                    Command="BadHabit_Factory:FactoryCommands.PlanSprint">
                    <MenuItem.Icon>
                        <Image Source="/Images/ToolBar/Plan.png" Stretch="Uniform" Width="32" Height="32"/>
                    </MenuItem.Icon>
                    
                </MenuItem>
                
                <MenuItem   
                    x:Name="autoPlanButton"                                       
                    BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                    Click="autoPlanButton_Click"
                    Header="{x:Static props:Resources.Auto_Plan}"                                     
                    Style="{StaticResource ToolBarMenuItem}"
                    ToolTip="{x:Static props:Resources.Auto_Plan_tooltip}"
                    IsCheckable="True">
                    <MenuItem.Icon>
                        <Image Source="/Images/ToolBar/Plan.png" Stretch="Uniform" Width="32" Height="32"/>
                    </MenuItem.Icon>
                </MenuItem>


                <MenuItem   
                    x:Name="exportProjectButton"                                      
                    BadHabit_WPFTools:RoleChecker.RequiredVisibleRole="SCRUM_MASTER"
                    Click="exportProjectButton_Click"
                    Header="{x:Static props:Resources.Export}"                                     
                    Style="{StaticResource ToolBarMenuItem}">
                    <MenuItem.Icon>
                        <Image Source="/Images/ToolBar/Export.png" Stretch="Uniform" Width="32" Height="32"/>
                    </MenuItem.Icon>
                </MenuItem>
                
                


            </Menu>

            <Separator/>

            
            <BadHabit_WPFTools:ComboBox
                x:Name="backlogFilterComboBox" 
                Width="200"
                            
                SelectedItem="{Binding ElementName=backlogDataGrid, Path=BacklogFilter}"                
                ItemsSource="{Binding Source={StaticResource BacklogFilterList}}"                
                SelectedItemTemplate="{StaticResource BacklogFilterSelectedItem}"
                ItemTemplate="{StaticResource BacklogFilterItem}"
                Style="{StaticResource FormComboBox}"/>    
            
</ToolBar>
            <Button
                        x:Name="commitButton"
                        DockPanel.Dock="Right"
                        Style="{StaticResource CommitButton}"
                        Command="ApplicationCommands.Save"
                        HorizontalAlignment="Right" 
                        Margin="5" />
        </DockPanel>

        <StackPanel Grid.Row="1" >
            <Border             
                DataContext="{Binding Project}">

                <TextBlock  VerticalAlignment="Top" TextWrapping="Wrap"
                           Text="{x:Static props:Resources.Sprint_planning_is_late}"/>                    

                <Border.Style>
                    <Style BasedOn="{StaticResource AlertBorder}" TargetType="Border" >
                        <Setter Property="Border.Visibility" Value="Collapsed"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsPlanningLate}" Value="True">
                                <Setter Property="Border.Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
            </Border>

            <Border DataContext="{Binding Project}">
                <TextBlock VerticalAlignment="Top" TextWrapping="Wrap"
                           Text="{x:Static props:Resources.Project_velocity_too_high}"/>                    
                
                <Border.Style>
                    <Style BasedOn="{StaticResource AlertBorder}" TargetType="Border" >
                        <Setter Property="Border.Visibility" Value="Collapsed"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding PlannedVelocity, Converter={StaticResource VelocityIsHigherConverter}}" Value="True">
                                <Setter Property="Border.Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>

            </Border>

            
        </StackPanel>
        

        


        <!--<Border
                Grid.Row="2"  
                Margin="3"
                CornerRadius="5,5,5,5" Padding="1,1,1,1" 
                Background="White"
                BorderBrush="{StaticResource ProjectPanelBorderBrush}" BorderThickness="1">-->
        <Border
                Grid.Row="2"                  
                Style="{StaticResource RoundBorder}">


            <BadHabit_Factory_Controls:BacklogDataGrid
                x:Name="backlogDataGrid"
                IsTabStop="False"
                AutoPlan="{Binding ElementName=autoPlanButton, Path=IsChecked}"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"/>
            

        </Border>


    </Grid>

    
    
</BadHabit_Factory_Controls:GenericPanel>